package com.swanclouds.redfish.chassis.domain;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonRootName;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.swanclouds.redfish.common.redfish.MemberModel;
import com.swanclouds.redfish.common.redfish.Status;

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;


/**
 *  * Description:
 *  * Author:      zhangliqiang@asiacom.net.cn
 *  * Date:        2022-07-17 11:26.
 *  
 */
public class NetworkAdaptersModel {

//    /**网络适配器资源的访问路径**/
//    @JsonProperty("@odata.id")
//    private String dataId;
//
//    /**网络适配器资源模型的OData描述信息**/
//    @JsonProperty("@odata.context")
//    private String context;
//
//    /**网络适配器资源的类型**/
//    @JsonProperty("@odata.type")
//    private String type;

    /**网络适配器资源ID**/
    @JsonProperty("Id")
    private String id;

    /**网络适配器资源名称**/
    @JsonProperty("Name")
    private String name;

    /**指定网络适配器的芯片制造商**/
    @JsonProperty("Manufacturer")
    private String manufacturer;

    /**指定网络适配器的型号**/
    @JsonProperty("Model")
    private String model;

    /**指定网络适配器自定义信息**/
    @JsonProperty("Oem")
    private NetworkAdapterOem oem;

    /**描述适配器控制器的信息**/
    @JsonProperty("Controllers")
    private List<Controller> controllers;

    /**网络适配器的状态，
     包括：
     ● Health：网络适
     配器健康状态
     ● State：网络适配
     器使能状态
     ● Severity：网络适
     配器的自定义健康状态**/
    @JsonProperty("Status")
    private Status status;

    /**网络适配器资源的访问路径**/
    @JsonProperty("NetworkPorts")
    private List<MemberModel> networkPorts;


    public String getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public String getManufacturer() {
        return manufacturer;
    }

    public String getModel() {
        return model;
    }

    public NetworkAdapterOem getOem() {
        return oem;
    }

    public List<Controller> getControllers() {
        return controllers;
    }

    public Status getStatus() {
        return status;
    }

    public List<String> getNetworkPorts() {
        return this.networkPorts.stream().map(MemberModel::getDataId).collect(Collectors.toList());
    }

    @Override
    public String toString() {
        ObjectMapper objectMapper = new ObjectMapper();
        try {
            return objectMapper.writeValueAsString(this);
        } catch (JsonProcessingException e) {
        }
        return "NetworkAdaptersModel {" +
                " id='" + id + '\'' +
                ", name='" + name + '\'' +
                ", manufacturer='" + manufacturer + '\'' +
                ", model='" + model + '\'' +
                ", oem=" + oem +
                ", controllers=" + controllers +
                ", status=" + status +
                ", networkPorts=" + networkPorts +
                '}';
    }

    @JsonRootName("Oem")
    public static class NetworkAdapterOem {

        @JsonProperty("BMC")
        private NetworkAdapterBmc bmc;

        @JsonProperty("Huawei")
        private NetworkAdapterHuawei huawei;

        public NetworkAdapterBmc getBmc() {
            return this.bmc;
        }

        public void setBmc(NetworkAdapterBmc bmc) {
            this.bmc = bmc;
        }

        public NetworkAdapterHuawei getHuawei() {
            return this.huawei;
        }

        public void setHuawei(NetworkAdapterHuawei huawei) {
            this.huawei = huawei;
        }

        @JsonRootName("BMC")
        public static class NetworkAdapterBmc {
            /**
             * 网络适配器的对外名称
             */
            @JsonProperty("Name")
            private String name;
            /**
             * 网络适配器的驱动名称
             */
            @JsonProperty("DriverName")
            private String driverName;
            /**
             * 网络适配器的驱动版本
             */
            @JsonProperty("DriverVersion")
            private String driverVersion;
            /**
             * 网络适配器的厂商
             */
            @JsonProperty("CardManufacturer")
            private String cardManufacturer;
            /**
             *   网络适配器的接口类型
             */
            @JsonProperty("CardModel")
            private String cardModel;
            /**
             * 网络适配器的丝印
             */
            @JsonProperty("DeviceLocator")
            private String deviceLocator;
            /**
             * 网络适配器的容器
             */
            @JsonProperty("Position")
            private String position;
            /**
             * 网络适配器的网络协议[ Ethernet, FC， iSCSI， FCoE， OPA， IB ]
             */
            @JsonProperty("NetworkTechnology")
            private List<String> networkTechnology;
            /**
             *
             */
            @JsonProperty("RootBDF")
            private String rootBDF;
            /**
             *
             */
            @JsonProperty("Configuration")
            private Configuration configuration;

            public String getName() {
                return this.name;
            }

            public void setName(String name) {
                this.name = name;
            }

            public String getDriverName() {
                return this.driverName;
            }

            public void setDriverName(String driverName) {
                this.driverName = driverName;
            }

            public String getDriverVersion() {
                return this.driverVersion;
            }

            public void setDriverVersion(String driverVersion) {
                this.driverVersion = driverVersion;
            }

            public String getCardManufacturer() {
                return this.cardManufacturer;
            }

            public void setCardManufacturer(String cardManufacturer) {
                this.cardManufacturer = cardManufacturer;
            }

            public String getCardModel() {
                return this.cardModel;
            }

            public void setCardModel(String cardModel) {
                this.cardModel = cardModel;
            }

            public String getDeviceLocator() {
                return this.deviceLocator;
            }

            public void setDeviceLocator(String deviceLocator) {
                this.deviceLocator = deviceLocator;
            }

            public String getPosition() {
                return this.position;
            }

            public void setPosition(String position) {
                this.position = position;
            }

            public List<String> getNetworkTechnology() {
                return this.networkTechnology;
            }

            public void setNetworkTechnology(List<String> networkTechnology) {
                this.networkTechnology = networkTechnology;
            }

            public String getRootBDF() {
                return this.rootBDF;
            }

            public void setRootBDF(String rootBDF) {
                this.rootBDF = rootBDF;
            }

            public Configuration getConfiguration() {
                return this.configuration;
            }

            public void setConfiguration(Configuration configuration) {
                this.configuration = configuration;
            }

            @JsonRootName("Configuration")
            public static class Configuration {

            }


        }

        @JsonRootName("Huawei")
        public static class NetworkAdapterHuawei {
            /**
             * 网络适配器的对外名称
             */
            @JsonProperty("Name")
            private String name;
            /**
             * 网络适配器的驱动名称
             */
            @JsonProperty("DriverName")
            private String driverName;
            /**
             * 网络适配器的驱动版本
             */
            @JsonProperty("DriverVersion")
            private String driverVersion;
            /**
             * 网络适配器的厂商
             */
            @JsonProperty("CardManufacturer")
            private String cardManufacturer;
            /**
             *   网络适配器的接口类型
             */
            @JsonProperty("CardModel")
            private String cardModel;
            /**
             * 网络适配器的丝印
             */
            @JsonProperty("DeviceLocator")
            private String deviceLocator;
            /**
             * 网络适配器的容器
             */
            @JsonProperty("Position")
            private String position;
            /**
             * 网络适配器的网络协议[ Ethernet, FC， iSCSI， FCoE， OPA， IB ]
             */
            @JsonProperty("NetworkTechnology")
            private List<String> networkTechnology;
            /**
             *
             */
            @JsonProperty("RootBDF")
            private String rootBDF;
            /**
             *
             */
            @JsonProperty("Configuration")
            private Configuration configuration;

            public String getName() {
                return this.name;
            }

            public void setName(String name) {
                this.name = name;
            }

            public String getDriverName() {
                return this.driverName;
            }

            public void setDriverName(String driverName) {
                this.driverName = driverName;
            }

            public String getDriverVersion() {
                return this.driverVersion;
            }

            public void setDriverVersion(String driverVersion) {
                this.driverVersion = driverVersion;
            }

            public String getCardManufacturer() {
                return this.cardManufacturer;
            }

            public void setCardManufacturer(String cardManufacturer) {
                this.cardManufacturer = cardManufacturer;
            }

            public String getCardModel() {
                return this.cardModel;
            }

            public void setCardModel(String cardModel) {
                this.cardModel = cardModel;
            }

            public String getDeviceLocator() {
                return this.deviceLocator;
            }

            public void setDeviceLocator(String deviceLocator) {
                this.deviceLocator = deviceLocator;
            }

            public String getPosition() {
                return this.position;
            }

            public void setPosition(String position) {
                this.position = position;
            }

            public List<String> getNetworkTechnology() {
                return this.networkTechnology;
            }

            public void setNetworkTechnology(List<String> networkTechnology) {
                this.networkTechnology = networkTechnology;
            }

            public String getRootBDF() {
                return this.rootBDF;
            }

            public void setRootBDF(String rootBDF) {
                this.rootBDF = rootBDF;
            }

            public Configuration getConfiguration() {
                return this.configuration;
            }

            public void setConfiguration(Configuration configuration) {
                this.configuration = configuration;
            }

            @JsonRootName("Configuration")
            public static class Configuration {

            }
        }
    }

    public static class Controller {
        /**指定网络适配器的固件版本**/
        @JsonProperty("FirmwarePackageVersion")
        private String firmwarePackageVersion;

        @JsonProperty("Link")
        private Link link;

        public String getFirmwarePackageVersion() {
            return this.firmwarePackageVersion;
        }

        public void setFirmwarePackageVersion(String firmwarePackageVersion) {
            this.firmwarePackageVersion = firmwarePackageVersion;
        }

        public Link getLink() {
            return this.link;
        }

        public void setLink(Link link) {
            this.link = link;
        }

        @JsonRootName("Link")
        public static class Link {
            @JsonProperty("PCIeDevices@odata.count")
            private int pcieDeviceCount;

            @JsonProperty("PCIeDevices")
            private List<MemberModel> list;
            private List<String> pCIeDevices;

            @JsonProperty("NetworkPorts@odata.count")
            private int networkPortCount;

            @JsonProperty("NetworkPorts")
            private List<MemberModel> memberModelList;
            private List<String> networkPorts;

            public int getPcieDeviceCount() {
                return this.pcieDeviceCount;
            }

            public void setPcieDeviceCount(int pcieDeviceCount) {
                this.pcieDeviceCount = pcieDeviceCount;
            }

            public List<MemberModel> getList() {
                return this.list;
            }

            public void setList(List<MemberModel> list) {
                this.list = list;
            }

            public List<String> getpCIeDevices() {
                if (Objects.nonNull(this.list)) {
                    this.pCIeDevices = this.list.stream().map(MemberModel::getDataId).collect(Collectors.toList());
                }
                return this.pCIeDevices;
            }

            public int getNetworkPortCount() {
                return this.networkPortCount;
            }

            public void setNetworkPortCount(int networkPortCount) {
                this.networkPortCount = networkPortCount;
            }

            public List<MemberModel> getMemberModelList() {
                return this.memberModelList;
            }

            public void setMemberModelList(List<MemberModel> memberModelList) {
                this.memberModelList = memberModelList;
            }

            public List<String> getNetworkPorts() {
                if (Objects.nonNull(this.memberModelList)) {
                    this.networkPorts = memberModelList.stream().map(MemberModel::getDataId).collect(Collectors.toList());
                }
                return this.networkPorts;
            }

        }
    }
}
